{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>candle_begin_time</th>\n",
       "      <th>symbol</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-24 16:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>1.97e-04</td>\n",
       "      <td>1.97e-04</td>\n",
       "      <td>3.01e-05</td>\n",
       "      <td>1.35e-04</td>\n",
       "      <td>27949.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-01-24 17:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.90e-05</td>\n",
       "      <td>9.99e-05</td>\n",
       "      <td>4.70e-05</td>\n",
       "      <td>5.60e-05</td>\n",
       "      <td>51104.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-01-24 18:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>6.30e-05</td>\n",
       "      <td>7.47e-05</td>\n",
       "      <td>5.01e-05</td>\n",
       "      <td>7.18e-05</td>\n",
       "      <td>106084.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-01-24 19:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.17e-05</td>\n",
       "      <td>7.33e-05</td>\n",
       "      <td>6.11e-05</td>\n",
       "      <td>7.04e-05</td>\n",
       "      <td>60643.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-01-24 20:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.00e-05</td>\n",
       "      <td>7.70e-05</td>\n",
       "      <td>6.10e-05</td>\n",
       "      <td>6.10e-05</td>\n",
       "      <td>26093.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2145</th>\n",
       "      <td>2018-01-24 19:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.60e+00</td>\n",
       "      <td>1.62e+00</td>\n",
       "      <td>1.58e+00</td>\n",
       "      <td>1.62e+00</td>\n",
       "      <td>8728.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2146</th>\n",
       "      <td>2018-01-24 20:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.61e+00</td>\n",
       "      <td>1.66e+00</td>\n",
       "      <td>1.61e+00</td>\n",
       "      <td>1.66e+00</td>\n",
       "      <td>45549.64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2147</th>\n",
       "      <td>2018-01-24 21:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>1.70e+00</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>1.67e+00</td>\n",
       "      <td>95792.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2148</th>\n",
       "      <td>2018-01-24 22:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.66e+00</td>\n",
       "      <td>1.68e+00</td>\n",
       "      <td>1.64e+00</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>21623.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2149</th>\n",
       "      <td>2018-01-24 23:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>1.68e+00</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>1.68e+00</td>\n",
       "      <td>1202.25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2150 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        candle_begin_time  symbol      open      high       low     close     volume\n",
       "0     2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99\n",
       "1     2018-01-24 17:00:00  AIDBTC  7.90e-05  9.99e-05  4.70e-05  5.60e-05   51104.00\n",
       "2     2018-01-24 18:00:00  AIDBTC  6.30e-05  7.47e-05  5.01e-05  7.18e-05  106084.15\n",
       "3     2018-01-24 19:00:00  AIDBTC  7.17e-05  7.33e-05  6.11e-05  7.04e-05   60643.77\n",
       "4     2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50\n",
       "...                   ...     ...       ...       ...       ...       ...        ...\n",
       "2145  2018-01-24 19:00:00  ZRXUSD  1.60e+00  1.62e+00  1.58e+00  1.62e+00    8728.98\n",
       "2146  2018-01-24 20:00:00  ZRXUSD  1.61e+00  1.66e+00  1.61e+00  1.66e+00   45549.64\n",
       "2147  2018-01-24 21:00:00  ZRXUSD  1.65e+00  1.70e+00  1.65e+00  1.67e+00   95792.54\n",
       "2148  2018-01-24 22:00:00  ZRXUSD  1.66e+00  1.68e+00  1.64e+00  1.65e+00   21623.11\n",
       "2149  2018-01-24 23:00:00  ZRXUSD  1.65e+00  1.68e+00  1.65e+00  1.68e+00    1202.25\n",
       "\n",
       "[2150 rows x 7 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 对print出的数据格式进行修正\n",
    "pd.set_option('expand_frame_repr', False)  # 当列太多时不换行\n",
    "pd.set_option('precision', 2)  # 浮点数的精度\n",
    "pd.set_option('display.max_rows', 10) # 显示的最大行数\n",
    "\n",
    "# =====导入数据\n",
    "df = pd.read_csv(\n",
    "    r'C:\\notebooks\\quantitative_trading_notes\\data\\BITFINEX-1H-data-20180124.csv',\n",
    "    skiprows=1,\n",
    "    # nrows=15,\n",
    ")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "        candle_begin_time  symbol      open      high       low     close   volume\n",
      "258   2018-01-24 00:00:00  BTCUSD  10812.00  10906.00  10522.00  10580.00  2616.12\n",
      "259   2018-01-24 01:00:00  BTCUSD  10581.00  10829.00  10522.00  10589.00  2562.01\n",
      "260   2018-01-24 02:00:00  BTCUSD  10588.00  10768.00  10518.33  10739.00  2043.93\n",
      "261   2018-01-24 03:00:00  BTCUSD  10739.00  10861.00  10615.00  10810.00  1137.69\n",
      "262   2018-01-24 04:00:00  BTCUSD  10809.00  10813.00  10430.00  10631.00  2251.18\n",
      "...                   ...     ...       ...       ...       ...       ...      ...\n",
      "1063  2018-01-24 19:00:00  LTCUSD    177.61    180.00    177.36    179.65  2652.16\n",
      "1064  2018-01-24 20:00:00  LTCUSD    179.64    181.48    179.51    180.23  4372.81\n",
      "1065  2018-01-24 21:00:00  LTCUSD    180.63    181.35    179.88    181.35  5317.36\n",
      "1066  2018-01-24 22:00:00  LTCUSD    181.35    181.54    178.35    178.70  6253.98\n",
      "1067  2018-01-24 23:00:00  LTCUSD    178.89    180.71    177.59    180.36  5359.13\n",
      "\n",
      "[72 rows x 7 columns]\n"
     ]
    }
   ],
   "source": [
    "print(df[df['symbol'].isin(['BTCUSD', 'LTCUSD', 'ETHUSD'])])  # 选取代码等于'BTCUSD'或'LTCUSD '或'ETHUSD'的行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        True\n",
       "1        True\n",
       "2        True\n",
       "3        True\n",
       "4        True\n",
       "        ...  \n",
       "2145    False\n",
       "2146    False\n",
       "2147    False\n",
       "2148    False\n",
       "2149    False\n",
       "Name: symbol, Length: 2150, dtype: bool"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['symbol'] == 'AIDBTC'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>candle_begin_time</th>\n",
       "      <th>symbol</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-24 16:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>1.97e-04</td>\n",
       "      <td>1.97e-04</td>\n",
       "      <td>3.01e-05</td>\n",
       "      <td>1.35e-04</td>\n",
       "      <td>27949.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-01-24 17:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.90e-05</td>\n",
       "      <td>9.99e-05</td>\n",
       "      <td>4.70e-05</td>\n",
       "      <td>5.60e-05</td>\n",
       "      <td>51104.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-01-24 18:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>6.30e-05</td>\n",
       "      <td>7.47e-05</td>\n",
       "      <td>5.01e-05</td>\n",
       "      <td>7.18e-05</td>\n",
       "      <td>106084.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-01-24 19:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.17e-05</td>\n",
       "      <td>7.33e-05</td>\n",
       "      <td>6.11e-05</td>\n",
       "      <td>7.04e-05</td>\n",
       "      <td>60643.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-01-24 20:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.00e-05</td>\n",
       "      <td>7.70e-05</td>\n",
       "      <td>6.10e-05</td>\n",
       "      <td>6.10e-05</td>\n",
       "      <td>26093.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2018-01-24 21:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>6.10e-05</td>\n",
       "      <td>6.81e-05</td>\n",
       "      <td>6.00e-05</td>\n",
       "      <td>6.79e-05</td>\n",
       "      <td>1332.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2018-01-24 22:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>6.30e-05</td>\n",
       "      <td>7.28e-05</td>\n",
       "      <td>5.50e-05</td>\n",
       "      <td>7.28e-05</td>\n",
       "      <td>31376.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2018-01-24 23:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.27e-05</td>\n",
       "      <td>7.28e-05</td>\n",
       "      <td>6.50e-05</td>\n",
       "      <td>6.91e-05</td>\n",
       "      <td>19032.53</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     candle_begin_time  symbol      open      high       low     close     volume\n",
       "0  2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99\n",
       "1  2018-01-24 17:00:00  AIDBTC  7.90e-05  9.99e-05  4.70e-05  5.60e-05   51104.00\n",
       "2  2018-01-24 18:00:00  AIDBTC  6.30e-05  7.47e-05  5.01e-05  7.18e-05  106084.15\n",
       "3  2018-01-24 19:00:00  AIDBTC  7.17e-05  7.33e-05  6.11e-05  7.04e-05   60643.77\n",
       "4  2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50\n",
       "5  2018-01-24 21:00:00  AIDBTC  6.10e-05  6.81e-05  6.00e-05  6.79e-05    1332.15\n",
       "6  2018-01-24 22:00:00  AIDBTC  6.30e-05  7.28e-05  5.50e-05  7.28e-05   31376.83\n",
       "7  2018-01-24 23:00:00  AIDBTC  7.27e-05  7.28e-05  6.50e-05  6.91e-05   19032.53"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df[某些条件]\n",
    "df[df['symbol'] == 'AIDBTC']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>candle_begin_time</th>\n",
       "      <th>symbol</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>210</th>\n",
       "      <td>2018-01-24 00:00:00</td>\n",
       "      <td>BCHUSD</td>\n",
       "      <td>1613.1</td>\n",
       "      <td>1624.9</td>\n",
       "      <td>1567.0</td>\n",
       "      <td>1568.0</td>\n",
       "      <td>1845.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>211</th>\n",
       "      <td>2018-01-24 01:00:00</td>\n",
       "      <td>BCHUSD</td>\n",
       "      <td>1567.9</td>\n",
       "      <td>1599.0</td>\n",
       "      <td>1550.4</td>\n",
       "      <td>1555.8</td>\n",
       "      <td>1520.57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>212</th>\n",
       "      <td>2018-01-24 02:00:00</td>\n",
       "      <td>BCHUSD</td>\n",
       "      <td>1558.2</td>\n",
       "      <td>1582.1</td>\n",
       "      <td>1552.6</td>\n",
       "      <td>1582.1</td>\n",
       "      <td>749.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>213</th>\n",
       "      <td>2018-01-24 03:00:00</td>\n",
       "      <td>BCHUSD</td>\n",
       "      <td>1583.4</td>\n",
       "      <td>1615.0</td>\n",
       "      <td>1577.9</td>\n",
       "      <td>1605.9</td>\n",
       "      <td>391.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>214</th>\n",
       "      <td>2018-01-24 04:00:00</td>\n",
       "      <td>BCHUSD</td>\n",
       "      <td>1605.9</td>\n",
       "      <td>1605.9</td>\n",
       "      <td>1565.0</td>\n",
       "      <td>1580.3</td>\n",
       "      <td>1151.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>707</th>\n",
       "      <td>2018-01-24 19:00:00</td>\n",
       "      <td>ETHUSD</td>\n",
       "      <td>1021.3</td>\n",
       "      <td>1033.6</td>\n",
       "      <td>1017.0</td>\n",
       "      <td>1032.0</td>\n",
       "      <td>5355.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>708</th>\n",
       "      <td>2018-01-24 20:00:00</td>\n",
       "      <td>ETHUSD</td>\n",
       "      <td>1031.9</td>\n",
       "      <td>1038.5</td>\n",
       "      <td>1026.6</td>\n",
       "      <td>1029.9</td>\n",
       "      <td>3076.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709</th>\n",
       "      <td>2018-01-24 21:00:00</td>\n",
       "      <td>ETHUSD</td>\n",
       "      <td>1030.0</td>\n",
       "      <td>1046.0</td>\n",
       "      <td>1030.0</td>\n",
       "      <td>1040.3</td>\n",
       "      <td>7307.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>710</th>\n",
       "      <td>2018-01-24 22:00:00</td>\n",
       "      <td>ETHUSD</td>\n",
       "      <td>1038.6</td>\n",
       "      <td>1042.1</td>\n",
       "      <td>1030.6</td>\n",
       "      <td>1033.9</td>\n",
       "      <td>1978.17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>711</th>\n",
       "      <td>2018-01-24 23:00:00</td>\n",
       "      <td>ETHUSD</td>\n",
       "      <td>1033.9</td>\n",
       "      <td>1063.3</td>\n",
       "      <td>1033.9</td>\n",
       "      <td>1061.6</td>\n",
       "      <td>7854.75</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>120 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       candle_begin_time  symbol    open    high     low   close   volume\n",
       "210  2018-01-24 00:00:00  BCHUSD  1613.1  1624.9  1567.0  1568.0  1845.39\n",
       "211  2018-01-24 01:00:00  BCHUSD  1567.9  1599.0  1550.4  1555.8  1520.57\n",
       "212  2018-01-24 02:00:00  BCHUSD  1558.2  1582.1  1552.6  1582.1   749.79\n",
       "213  2018-01-24 03:00:00  BCHUSD  1583.4  1615.0  1577.9  1605.9   391.01\n",
       "214  2018-01-24 04:00:00  BCHUSD  1605.9  1605.9  1565.0  1580.3  1151.29\n",
       "..                   ...     ...     ...     ...     ...     ...      ...\n",
       "707  2018-01-24 19:00:00  ETHUSD  1021.3  1033.6  1017.0  1032.0  5355.05\n",
       "708  2018-01-24 20:00:00  ETHUSD  1031.9  1038.5  1026.6  1029.9  3076.12\n",
       "709  2018-01-24 21:00:00  ETHUSD  1030.0  1046.0  1030.0  1040.3  7307.24\n",
       "710  2018-01-24 22:00:00  ETHUSD  1038.6  1042.1  1030.6  1033.9  1978.17\n",
       "711  2018-01-24 23:00:00  ETHUSD  1033.9  1063.3  1033.9  1061.6  7854.75\n",
       "\n",
       "[120 rows x 7 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df['close'] >= 500]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>candle_begin_time</th>\n",
       "      <th>symbol</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1044</th>\n",
       "      <td>2018-01-24 00:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>177.83</td>\n",
       "      <td>178.67</td>\n",
       "      <td>173.22</td>\n",
       "      <td>174.15</td>\n",
       "      <td>7133.57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1045</th>\n",
       "      <td>2018-01-24 01:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>174.30</td>\n",
       "      <td>176.89</td>\n",
       "      <td>172.00</td>\n",
       "      <td>172.90</td>\n",
       "      <td>3887.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1046</th>\n",
       "      <td>2018-01-24 02:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>172.95</td>\n",
       "      <td>175.96</td>\n",
       "      <td>172.31</td>\n",
       "      <td>175.32</td>\n",
       "      <td>5028.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1047</th>\n",
       "      <td>2018-01-24 03:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>175.32</td>\n",
       "      <td>178.00</td>\n",
       "      <td>174.01</td>\n",
       "      <td>177.10</td>\n",
       "      <td>3433.41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1048</th>\n",
       "      <td>2018-01-24 04:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>177.22</td>\n",
       "      <td>177.30</td>\n",
       "      <td>171.73</td>\n",
       "      <td>174.44</td>\n",
       "      <td>6690.65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063</th>\n",
       "      <td>2018-01-24 19:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>177.61</td>\n",
       "      <td>180.00</td>\n",
       "      <td>177.36</td>\n",
       "      <td>179.65</td>\n",
       "      <td>2652.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1064</th>\n",
       "      <td>2018-01-24 20:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>179.64</td>\n",
       "      <td>181.48</td>\n",
       "      <td>179.51</td>\n",
       "      <td>180.23</td>\n",
       "      <td>4372.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1065</th>\n",
       "      <td>2018-01-24 21:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>180.63</td>\n",
       "      <td>181.35</td>\n",
       "      <td>179.88</td>\n",
       "      <td>181.35</td>\n",
       "      <td>5317.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1066</th>\n",
       "      <td>2018-01-24 22:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>181.35</td>\n",
       "      <td>181.54</td>\n",
       "      <td>178.35</td>\n",
       "      <td>178.70</td>\n",
       "      <td>6253.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1067</th>\n",
       "      <td>2018-01-24 23:00:00</td>\n",
       "      <td>LTCUSD</td>\n",
       "      <td>178.89</td>\n",
       "      <td>180.71</td>\n",
       "      <td>177.59</td>\n",
       "      <td>180.36</td>\n",
       "      <td>5359.13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>24 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        candle_begin_time  symbol    open    high     low   close   volume\n",
       "1044  2018-01-24 00:00:00  LTCUSD  177.83  178.67  173.22  174.15  7133.57\n",
       "1045  2018-01-24 01:00:00  LTCUSD  174.30  176.89  172.00  172.90  3887.90\n",
       "1046  2018-01-24 02:00:00  LTCUSD  172.95  175.96  172.31  175.32  5028.80\n",
       "1047  2018-01-24 03:00:00  LTCUSD  175.32  178.00  174.01  177.10  3433.41\n",
       "1048  2018-01-24 04:00:00  LTCUSD  177.22  177.30  171.73  174.44  6690.65\n",
       "...                   ...     ...     ...     ...     ...     ...      ...\n",
       "1063  2018-01-24 19:00:00  LTCUSD  177.61  180.00  177.36  179.65  2652.16\n",
       "1064  2018-01-24 20:00:00  LTCUSD  179.64  181.48  179.51  180.23  4372.81\n",
       "1065  2018-01-24 21:00:00  LTCUSD  180.63  181.35  179.88  181.35  5317.36\n",
       "1066  2018-01-24 22:00:00  LTCUSD  181.35  181.54  178.35  178.70  6253.98\n",
       "1067  2018-01-24 23:00:00  LTCUSD  178.89  180.71  177.59  180.36  5359.13\n",
       "\n",
       "[24 rows x 7 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df['symbol'] == 'LTCUSD') & (df['close'] <= 200)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>candle_begin_time</th>\n",
       "      <th>symbol</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>16h/20h</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-24 16:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>1.97e-04</td>\n",
       "      <td>1.97e-04</td>\n",
       "      <td>3.01e-05</td>\n",
       "      <td>1.35e-04</td>\n",
       "      <td>27949.99</td>\n",
       "      <td>2018-01-24 16:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-01-24 17:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.90e-05</td>\n",
       "      <td>9.99e-05</td>\n",
       "      <td>4.70e-05</td>\n",
       "      <td>5.60e-05</td>\n",
       "      <td>51104.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-01-24 18:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>6.30e-05</td>\n",
       "      <td>7.47e-05</td>\n",
       "      <td>5.01e-05</td>\n",
       "      <td>7.18e-05</td>\n",
       "      <td>106084.15</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-01-24 19:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.17e-05</td>\n",
       "      <td>7.33e-05</td>\n",
       "      <td>6.11e-05</td>\n",
       "      <td>7.04e-05</td>\n",
       "      <td>60643.77</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-01-24 20:00:00</td>\n",
       "      <td>AIDBTC</td>\n",
       "      <td>7.00e-05</td>\n",
       "      <td>7.70e-05</td>\n",
       "      <td>6.10e-05</td>\n",
       "      <td>6.10e-05</td>\n",
       "      <td>26093.50</td>\n",
       "      <td>2018-01-24 20:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2145</th>\n",
       "      <td>2018-01-24 19:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.60e+00</td>\n",
       "      <td>1.62e+00</td>\n",
       "      <td>1.58e+00</td>\n",
       "      <td>1.62e+00</td>\n",
       "      <td>8728.98</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2146</th>\n",
       "      <td>2018-01-24 20:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.61e+00</td>\n",
       "      <td>1.66e+00</td>\n",
       "      <td>1.61e+00</td>\n",
       "      <td>1.66e+00</td>\n",
       "      <td>45549.64</td>\n",
       "      <td>2018-01-24 20:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2147</th>\n",
       "      <td>2018-01-24 21:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>1.70e+00</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>1.67e+00</td>\n",
       "      <td>95792.54</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2148</th>\n",
       "      <td>2018-01-24 22:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.66e+00</td>\n",
       "      <td>1.68e+00</td>\n",
       "      <td>1.64e+00</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>21623.11</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2149</th>\n",
       "      <td>2018-01-24 23:00:00</td>\n",
       "      <td>ZRXUSD</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>1.68e+00</td>\n",
       "      <td>1.65e+00</td>\n",
       "      <td>1.68e+00</td>\n",
       "      <td>1202.25</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2150 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        candle_begin_time  symbol      open      high       low     close     volume              16h/20h\n",
       "0     2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99  2018-01-24 16:00:00\n",
       "1     2018-01-24 17:00:00  AIDBTC  7.90e-05  9.99e-05  4.70e-05  5.60e-05   51104.00                  NaN\n",
       "2     2018-01-24 18:00:00  AIDBTC  6.30e-05  7.47e-05  5.01e-05  7.18e-05  106084.15                  NaN\n",
       "3     2018-01-24 19:00:00  AIDBTC  7.17e-05  7.33e-05  6.11e-05  7.04e-05   60643.77                  NaN\n",
       "4     2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50  2018-01-24 20:00:00\n",
       "...                   ...     ...       ...       ...       ...       ...        ...                  ...\n",
       "2145  2018-01-24 19:00:00  ZRXUSD  1.60e+00  1.62e+00  1.58e+00  1.62e+00    8728.98                  NaN\n",
       "2146  2018-01-24 20:00:00  ZRXUSD  1.61e+00  1.66e+00  1.61e+00  1.66e+00   45549.64  2018-01-24 20:00:00\n",
       "2147  2018-01-24 21:00:00  ZRXUSD  1.65e+00  1.70e+00  1.65e+00  1.67e+00   95792.54                  NaN\n",
       "2148  2018-01-24 22:00:00  ZRXUSD  1.66e+00  1.68e+00  1.64e+00  1.65e+00   21623.11                  NaN\n",
       "2149  2018-01-24 23:00:00  ZRXUSD  1.65e+00  1.68e+00  1.65e+00  1.68e+00    1202.25                  NaN\n",
       "\n",
       "[2150 rows x 8 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df.loc[判断条件，列] = 赋值\n",
    "index = df[df['candle_begin_time'].isin(['2018-01-24 16:00:00','2018-01-24 20:00:00'])].index\n",
    "df.loc[index, '16h/20h'] = df['candle_begin_time']\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "        candle_begin_time  symbol      open      high       low     close     volume              16h/20h\n",
      "0     2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99  2018-01-24 16:00:00\n",
      "4     2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50  2018-01-24 20:00:00\n",
      "8     2018-01-24 16:00:00  AIDETH  5.46e-04  9.00e-04  5.10e-04  7.27e-04   53803.15  2018-01-24 16:00:00\n",
      "12    2018-01-24 20:00:00  AIDETH  7.00e-04  8.45e-04  5.11e-04  5.11e-04  271016.75  2018-01-24 20:00:00\n",
      "16    2018-01-24 16:00:00  AIDUSD  1.00e-01  8.47e-01  1.00e-01  5.53e-01  308668.33  2018-01-24 16:00:00\n",
      "...                   ...     ...       ...       ...       ...       ...        ...                  ...\n",
      "2103  2018-01-24 20:00:00  ZRXBTC  1.45e-04  1.49e-04  1.44e-04  1.47e-04   12296.24  2018-01-24 20:00:00\n",
      "2119  2018-01-24 16:00:00  ZRXETH  1.60e-03  1.61e-03  1.59e-03  1.59e-03   11224.92  2018-01-24 16:00:00\n",
      "2122  2018-01-24 20:00:00  ZRXETH  1.57e-03  1.57e-03  1.57e-03  1.57e-03    2397.00  2018-01-24 20:00:00\n",
      "2142  2018-01-24 16:00:00  ZRXUSD  1.63e+00  1.63e+00  1.59e+00  1.61e+00   58837.90  2018-01-24 16:00:00\n",
      "2146  2018-01-24 20:00:00  ZRXUSD  1.61e+00  1.66e+00  1.61e+00  1.66e+00   45549.64  2018-01-24 20:00:00\n",
      "\n",
      "[205 rows x 8 columns]\n",
      "        candle_begin_time  symbol      open      high       low     close     volume              16h/20h\n",
      "0     2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99  2018-01-24 16:00:00\n",
      "1     2018-01-24 17:00:00  AIDBTC  7.90e-05  9.99e-05  4.70e-05  5.60e-05   51104.00                  NaN\n",
      "2     2018-01-24 18:00:00  AIDBTC  6.30e-05  7.47e-05  5.01e-05  7.18e-05  106084.15                  NaN\n",
      "3     2018-01-24 19:00:00  AIDBTC  7.17e-05  7.33e-05  6.11e-05  7.04e-05   60643.77                  NaN\n",
      "4     2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50  2018-01-24 20:00:00\n",
      "...                   ...     ...       ...       ...       ...       ...        ...                  ...\n",
      "2145  2018-01-24 19:00:00  ZRXUSD  1.60e+00  1.62e+00  1.58e+00  1.62e+00    8728.98                  NaN\n",
      "2146  2018-01-24 20:00:00  ZRXUSD  1.61e+00  1.66e+00  1.61e+00  1.66e+00   45549.64  2018-01-24 20:00:00\n",
      "2147  2018-01-24 21:00:00  ZRXUSD  1.65e+00  1.70e+00  1.65e+00  1.67e+00   95792.54                  NaN\n",
      "2148  2018-01-24 22:00:00  ZRXUSD  1.66e+00  1.68e+00  1.64e+00  1.65e+00   21623.11                  NaN\n",
      "2149  2018-01-24 23:00:00  ZRXUSD  1.65e+00  1.68e+00  1.65e+00  1.68e+00    1202.25                  NaN\n",
      "\n",
      "[2150 rows x 8 columns]\n"
     ]
    }
   ],
   "source": [
    "# 删除na值  删除行的相关操作\n",
    "print(df.dropna(how='any'))  # 将带有空值的行删除。how='any'意味着，该行中只要有一个空值，就会删除，可以改成all。\n",
    "print(df.dropna(subset=['16h/20h', 'close'], how='all'))  # subset参数指定在特定的列中判断空值。\n",
    "# all代表全部为空，才会删除该行；any只要一个为空，就删除该行。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      candle_begin_time  symbol  open  high   low  close  volume  16h/20h\n",
      "0                  True    True  True  True  True   True    True     True\n",
      "1                  True    True  True  True  True   True    True    False\n",
      "2                  True    True  True  True  True   True    True    False\n",
      "3                  True    True  True  True  True   True    True    False\n",
      "4                  True    True  True  True  True   True    True     True\n",
      "...                 ...     ...   ...   ...   ...    ...     ...      ...\n",
      "2145               True    True  True  True  True   True    True    False\n",
      "2146               True    True  True  True  True   True    True     True\n",
      "2147               True    True  True  True  True   True    True    False\n",
      "2148               True    True  True  True  True   True    True    False\n",
      "2149               True    True  True  True  True   True    True    False\n",
      "\n",
      "[2150 rows x 8 columns]\n",
      "        candle_begin_time  symbol      open      high       low     close     volume              16h/20h\n",
      "0     2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99  2018-01-24 16:00:00\n",
      "4     2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50  2018-01-24 20:00:00\n",
      "8     2018-01-24 16:00:00  AIDETH  5.46e-04  9.00e-04  5.10e-04  7.27e-04   53803.15  2018-01-24 16:00:00\n",
      "12    2018-01-24 20:00:00  AIDETH  7.00e-04  8.45e-04  5.11e-04  5.11e-04  271016.75  2018-01-24 20:00:00\n",
      "16    2018-01-24 16:00:00  AIDUSD  1.00e-01  8.47e-01  1.00e-01  5.53e-01  308668.33  2018-01-24 16:00:00\n",
      "...                   ...     ...       ...       ...       ...       ...        ...                  ...\n",
      "2103  2018-01-24 20:00:00  ZRXBTC  1.45e-04  1.49e-04  1.44e-04  1.47e-04   12296.24  2018-01-24 20:00:00\n",
      "2119  2018-01-24 16:00:00  ZRXETH  1.60e-03  1.61e-03  1.59e-03  1.59e-03   11224.92  2018-01-24 16:00:00\n",
      "2122  2018-01-24 20:00:00  ZRXETH  1.57e-03  1.57e-03  1.57e-03  1.57e-03    2397.00  2018-01-24 20:00:00\n",
      "2142  2018-01-24 16:00:00  ZRXUSD  1.63e+00  1.63e+00  1.59e+00  1.61e+00   58837.90  2018-01-24 16:00:00\n",
      "2146  2018-01-24 20:00:00  ZRXUSD  1.61e+00  1.66e+00  1.61e+00  1.66e+00   45549.64  2018-01-24 20:00:00\n",
      "\n",
      "[205 rows x 8 columns]\n"
     ]
    }
   ],
   "source": [
    "# 找出缺失值\n",
    "print(df.notnull())  # 判断是否为空值，反向函数为isnull()\n",
    "print(df[df['16h/20h'].notnull()])  # 将'12小时'列为空的行输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "        candle_begin_time  symbol      open      high       low     close     volume              16h/20h\n",
      "0     2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99  2018-01-24 16:00:00\n",
      "1     2018-01-24 17:00:00  AIDBTC  7.90e-05  9.99e-05  4.70e-05  5.60e-05   51104.00                    0\n",
      "2     2018-01-24 18:00:00  AIDBTC  6.30e-05  7.47e-05  5.01e-05  7.18e-05  106084.15                    0\n",
      "3     2018-01-24 19:00:00  AIDBTC  7.17e-05  7.33e-05  6.11e-05  7.04e-05   60643.77                    0\n",
      "4     2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50  2018-01-24 20:00:00\n",
      "...                   ...     ...       ...       ...       ...       ...        ...                  ...\n",
      "2145  2018-01-24 19:00:00  ZRXUSD  1.60e+00  1.62e+00  1.58e+00  1.62e+00    8728.98                    0\n",
      "2146  2018-01-24 20:00:00  ZRXUSD  1.61e+00  1.66e+00  1.61e+00  1.66e+00   45549.64  2018-01-24 20:00:00\n",
      "2147  2018-01-24 21:00:00  ZRXUSD  1.65e+00  1.70e+00  1.65e+00  1.67e+00   95792.54                    0\n",
      "2148  2018-01-24 22:00:00  ZRXUSD  1.66e+00  1.68e+00  1.64e+00  1.65e+00   21623.11                    0\n",
      "2149  2018-01-24 23:00:00  ZRXUSD  1.65e+00  1.68e+00  1.65e+00  1.68e+00    1202.25                    0\n",
      "\n",
      "[2150 rows x 8 columns]\n",
      "        candle_begin_time  symbol      open      high       low     close     volume              16h/20h\n",
      "0     2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99  2018-01-24 16:00:00\n",
      "1     2018-01-24 17:00:00  AIDBTC  7.90e-05  9.99e-05  4.70e-05  5.60e-05   51104.00  2018-01-24 16:00:00\n",
      "2     2018-01-24 18:00:00  AIDBTC  6.30e-05  7.47e-05  5.01e-05  7.18e-05  106084.15  2018-01-24 16:00:00\n",
      "3     2018-01-24 19:00:00  AIDBTC  7.17e-05  7.33e-05  6.11e-05  7.04e-05   60643.77  2018-01-24 16:00:00\n",
      "4     2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50  2018-01-24 20:00:00\n",
      "...                   ...     ...       ...       ...       ...       ...        ...                  ...\n",
      "2145  2018-01-24 19:00:00  ZRXUSD  1.60e+00  1.62e+00  1.58e+00  1.62e+00    8728.98  2018-01-24 16:00:00\n",
      "2146  2018-01-24 20:00:00  ZRXUSD  1.61e+00  1.66e+00  1.61e+00  1.66e+00   45549.64  2018-01-24 20:00:00\n",
      "2147  2018-01-24 21:00:00  ZRXUSD  1.65e+00  1.70e+00  1.65e+00  1.67e+00   95792.54  2018-01-24 20:00:00\n",
      "2148  2018-01-24 22:00:00  ZRXUSD  1.66e+00  1.68e+00  1.64e+00  1.65e+00   21623.11  2018-01-24 20:00:00\n",
      "2149  2018-01-24 23:00:00  ZRXUSD  1.65e+00  1.68e+00  1.65e+00  1.68e+00    1202.25  2018-01-24 20:00:00\n",
      "\n",
      "[2150 rows x 8 columns]\n",
      "        candle_begin_time  symbol      open      high       low     close     volume              16h/20h\n",
      "0     2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99  2018-01-24 16:00:00\n",
      "1     2018-01-24 17:00:00  AIDBTC  7.90e-05  9.99e-05  4.70e-05  5.60e-05   51104.00  2018-01-24 20:00:00\n",
      "2     2018-01-24 18:00:00  AIDBTC  6.30e-05  7.47e-05  5.01e-05  7.18e-05  106084.15  2018-01-24 20:00:00\n",
      "3     2018-01-24 19:00:00  AIDBTC  7.17e-05  7.33e-05  6.11e-05  7.04e-05   60643.77  2018-01-24 20:00:00\n",
      "4     2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50  2018-01-24 20:00:00\n",
      "...                   ...     ...       ...       ...       ...       ...        ...                  ...\n",
      "2145  2018-01-24 19:00:00  ZRXUSD  1.60e+00  1.62e+00  1.58e+00  1.62e+00    8728.98  2018-01-24 20:00:00\n",
      "2146  2018-01-24 20:00:00  ZRXUSD  1.61e+00  1.66e+00  1.61e+00  1.66e+00   45549.64  2018-01-24 20:00:00\n",
      "2147  2018-01-24 21:00:00  ZRXUSD  1.65e+00  1.70e+00  1.65e+00  1.67e+00   95792.54                  NaN\n",
      "2148  2018-01-24 22:00:00  ZRXUSD  1.66e+00  1.68e+00  1.64e+00  1.65e+00   21623.11                  NaN\n",
      "2149  2018-01-24 23:00:00  ZRXUSD  1.65e+00  1.68e+00  1.65e+00  1.68e+00    1202.25                  NaN\n",
      "\n",
      "[2150 rows x 8 columns]\n",
      "        candle_begin_time  symbol      open      high       low     close     volume              16h/20h\n",
      "0     2018-01-24 16:00:00  AIDBTC  1.97e-04  1.97e-04  3.01e-05  1.35e-04   27949.99  2018-01-24 16:00:00\n",
      "1     2018-01-24 17:00:00  AIDBTC  7.90e-05  9.99e-05  4.70e-05  5.60e-05   51104.00              5.6e-05\n",
      "2     2018-01-24 18:00:00  AIDBTC  6.30e-05  7.47e-05  5.01e-05  7.18e-05  106084.15              7.2e-05\n",
      "3     2018-01-24 19:00:00  AIDBTC  7.17e-05  7.33e-05  6.11e-05  7.04e-05   60643.77                7e-05\n",
      "4     2018-01-24 20:00:00  AIDBTC  7.00e-05  7.70e-05  6.10e-05  6.10e-05   26093.50  2018-01-24 20:00:00\n",
      "...                   ...     ...       ...       ...       ...       ...        ...                  ...\n",
      "2145  2018-01-24 19:00:00  ZRXUSD  1.60e+00  1.62e+00  1.58e+00  1.62e+00    8728.98                  1.6\n",
      "2146  2018-01-24 20:00:00  ZRXUSD  1.61e+00  1.66e+00  1.61e+00  1.66e+00   45549.64  2018-01-24 20:00:00\n",
      "2147  2018-01-24 21:00:00  ZRXUSD  1.65e+00  1.70e+00  1.65e+00  1.67e+00   95792.54                  1.7\n",
      "2148  2018-01-24 22:00:00  ZRXUSD  1.66e+00  1.68e+00  1.64e+00  1.65e+00   21623.11                  1.7\n",
      "2149  2018-01-24 23:00:00  ZRXUSD  1.65e+00  1.68e+00  1.65e+00  1.68e+00    1202.25                  1.7\n",
      "\n",
      "[2150 rows x 8 columns]\n"
     ]
    }
   ],
   "source": [
    "# 补全na值\n",
    "print(df.fillna(value=0))  # 直接将缺失值赋值为固定的值\n",
    "\n",
    "print(df.fillna(method='ffill'))  # 向上寻找最近的一个非空值，以该值来填充缺失的位置，全称forward fill，非常有用\n",
    "print(df.fillna(method='bfill'))  # 向下寻找最近的一个非空值，以该值来填充确实的位置，全称backward fill\n",
    "\n",
    "df['16h/20h'].fillna(value=df['close'], inplace=True)\n",
    "print(df) # 直接将缺失值赋值其他列的数据"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
